import { Component, ChangeDetectionStrategy, ChangeDetectorRef, OnInit, Inject } from '@angular/core';
import { delay } from 'rxjs/operators';
import { NzMessageService } from 'ng-zorro-antd';
import { _HttpClient, TitleService, ModalHelper, SettingsService } from '@delon/theme';

import { DashboardHomeCustomComponent } from './custom/custom.component';
import { DOCUMENT } from '@angular/common';
import { BrandService } from '@brand';
import { UserService } from '@core';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class HomeComponent implements OnInit {
  data: any;
  recentlies = ['组件', 'Ng Alain', 'Smart', 'API 网关', '数据'];

  constructor(
    titSrv: TitleService,
    private modal: ModalHelper,
    private cdr: ChangeDetectorRef,
    public msg: NzMessageService,
    public http: _HttpClient,
    @Inject(DOCUMENT) private doc: any,
    private srv: BrandService,
    private settingService: SettingsService,
  ) {
    titSrv.setTitleByI18n('home.title');
  }

  get isMobile() {
    return this.srv.isMobile;
  }

  ngOnInit() {
    // this.http
    //   .get('/home')
    //   .pipe(delay(500))
    //   .subscribe(res => {
    //     this.data = res;
    //     this.cdr.detectChanges();
    //   });
    const guide = this.doc.querySelector('#J_guide_wrapper');
    if (!this.isMobile && guide && !window.localStorage.getItem(`${this.settingService.user.username}_iknowed`)) {
      guide.style.display = '';
      guide.setAttribute('data-username', `${this.settingService.user.username}`);
    }
  }

  openCustom() {
    this.modal.createStatic(DashboardHomeCustomComponent, {}, { size: 'md' }).subscribe(res => {
      this.msg.success(JSON.stringify(res));
    });
  }
}
